package p.ithorns.example.validator;

import javax.validation.Constraint;
import javax.validation.Payload;
import java.lang.annotation.*;

/**
 * FieldAssociated
 * 字段关联校验
 *
 * @author HtL
 * @date 2025/3/13 15:14
 * @since 1.0.0
 */
@Documented
@Target({ElementType.TYPE_USE})
@Retention(RetentionPolicy.RUNTIME)
@Constraint(validatedBy = {FieldAssociatedValidator.class})
@Repeatable(FieldAssociated.List.class)
public @interface FieldAssociated {
    /**
     * 目标字段
     */
    String target();
    /**
     * 决策字段条件
     */
    String when();
    /**
     * 校验字段条件
     */
    String then();

    String message() default "{target}:字段校验失败";

    Class<?>[] groups() default {};

    Class<? extends Payload>[] payload() default {};


    @Target({ElementType.TYPE_USE})
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    @interface List {
        FieldAssociated[] value();
    }
}